import axios from './request';
// 获取精品课程
export async function getExcellentCourse ({ tags, pageNum, pageSize, type, status }) {
  const { data } = await axios.get(`${process.env.VUE_APP_NRMS_URL}/rms/v1/catalogue/list_course`, {
    params: {
      tags,
      pageNum,
      pageSize,
      type,
      status
    }
  });
  return data;
}
// 查询精品课程学习人次及是否学习接口，type:  1 仅获取学习人次 2 标记是否已经学习 3 标记+人次c; catalogueIds: 课程id集合使用,分隔
export async function getStudentNum ({ catalogueIds, type }) {
  const { data } = await axios.get(`${process.env.VUE_APP_NRMS_URL}/rms/v1/catalogue/list_learn`, {
    params: {
      catalogueIds,
      type
    }
  });
  return data;
}
// 查询精品课程详情接口，ossType:  0 全国 1 省级
export async function getCourseDetail ({ courseId, ossType }) {
  const { data } = await axios.get(`${process.env.VUE_APP_NRMS_URL}/rms/v1/qualitycourse/course_info`, {
    params: {
      courseId,
      ossType
    }
  });
  return data;
}
// 根据书本id/学科产品id查询宣导图和宣导视频
export async function promoteInfoById ({ id }) {
  const { data } = await axios.get(`${process.env.VUE_APP_NRMS_URL}/rms/v1/catalogue/promoteInfo_by_id`, {
    params: {
      id
    }
  });
  return data;
}
// 获取目录树
export async function getCatalogTree ({ bookId, type }) {
  const { data } = await axios.get(`${process.env.VUE_APP_NRMS_URL}/rms/v1/catalogue/list_cata_logue`, {
    params: { bookId, type }
  });
  return data;
}
// 获取目录下面的资源信息
export async function getSource ({ catalogueIds }) {
  const { data } = await axios.get(`${process.env.VUE_APP_NRMS_URL}/rms/v1/qualitycourse/list_res`, {
    params: { catalogueIds }
  });
  return data;
}
export async function addRecord ({ catId, resId, resType, purpose, spendTime, duration }) {
  const { data } = await axios.post(`${process.env.VUE_APP_NRMS_URL}/rms/v1/cat_records/add_record`, {
    catId,
    resId,
    resType,
    purpose,
    spendTime,
    duration
  });
  return data;
}
/*
 *家辅app首页推荐列表接口
 *@functionName: getCrouseList
 *@params1: section 学段 grade 年级 volume 学期
 *@author: libaochuan
 *@date: 2021-05-18 08:50:40
 */
 export async function getListRecommend ({ section, grade, volume }) {
  const { data } = await axios.get(`${process.env.VUE_APP_NRMS_URL}/rms/v1/catalogue/list_recommend`, {
    params: {
      section,
      grade,
      volume
    }
  });
  return data;
}
/*
 *家辅app首页推荐列表接口
 *@functionName: getListSubjectSpecial
 *@params1: section 学段 grade 年级 volume 学期 subject 学科
 *@author: libaochuan
 *@date: 2021-05-18 08:50:40
 */
 export async function getListSubjectSpecial ({ section, grade, volume, subject, version }) {
  const { data } = await axios.get(`${process.env.VUE_APP_NRMS_URL}/rms/v1/catalogue/list_subject_special`, {
    params: {
      section,
      grade,
      volume,
      subject,
      version
    }
  });
  return data;
}
/*
 *@functionName: getCrouseList
 *@params1: tags  标签组合条件，标签编码-标签枚举编码，多个逗号分隔
 *@params2: pageNum  当前页
 *@params3: pageSize  每页显示条数
 *@params4: type   3 专项课程 4 同步课程 不传默认两个都查询
 *@params4: status  目录状态1 启用,0禁用 这里传1 仅查询启用状态的目录
 *@description:根据标签查询课程列表接口
 *@author: wudandan
 *@date: 2021-03-09 08:50:40
 */
export async function getCrouseList ({ tags, pageNum, pageSize, type, status }) {
  const { data } = await axios.get(`${process.env.VUE_APP_NRMS_URL}/rms/v1/catalogue/list_course`, {
    params: {
      tags,
      pageNum,
      pageSize,
      type,
      status
    }
  });
  return data;
}
/*
 *@functionName: getSyncCrouseTree
 *@params1: bookId
 *@params2: isNew  是否标记new  0-是 ，1-否
 *@description:根据同步课程编码获取同步课程目录接口
 *@author: wudandan
 *@date: 2021-03-09 09:00:14
 */
export async function getSyncCrouseTree ({ bookId, isNew }) {
  const { data } = await axios.get(`${process.env.VUE_APP_NRMS_URL}/rms/v1/catalogue/list_sync_course`, {
    params: {
      bookId,
      isNew
    }
  });
  return data;
}
/*
 *@functionName: getCrouseRes
 *@params1: catalogueIds
 *@params2: type
 *@params3: isNew
 *@params3: isRecursive  是否递归查询 0-是 1-否
 *@description:根据目录编码获取目录下模块环节及资源接口
 *@author: wudandan
 *@date: 2021-03-09 09:20:03
 */
export async function getCrouseRes ({ catalogueIds, type, isNew, isRecursive }) {
  const { data } = await axios.get(`${process.env.VUE_APP_NRMS_URL}/rms/v1/catalogue/list_res_group_by_tag`, {
    params: {
      catalogueIds,
      type,
      isNew,
      isRecursive
    }
  });
  return data;
}
/*
 *@functionName: getResRecords
 *@params1: resIds 资源编码 多个逗号分隔
 *@params2: purpose 用途：1 是通用 2 传递辅导模块 3 版本目录进度,4 精品课程进度，5.资源学习进度
 *@params3: size 返回最大条数
 *@description:获取特定用户指定资源的学习进度记录
 *@author: wudandan
 *@date: 2021-03-09 17:03:41
 */
export async function getResRecords ({ resIds, purpose, size }) {
  const { data } = await axios.get(`${process.env.VUE_APP_NRMS_URL}/rms/v1/cat_records/list_res_records`, {
    params: {
      resIds,
      purpose,
      size
    }
  });
  return data;
}

/*
 *@functionName: getUsedCatalog
  *@params1: bookId
 *@description:查询用户教材目录进度
 *@author: wudandan
 *@date: 2020-09-09 13:59:02
*/
export async function getUsedCatalog (bookId) {
  const { data } = await axios.get(`${process.env.VUE_APP_UC_URL}/isch-c/user/book/progress/${bookId}`);
  return data;
}
/*
 *@functionName: updateUseCatalog
 *@params1: bookId
 *@params2: catalogId
 *@description:更新用户教材目录进度
 *@author: wudandan
 *@date: 2020-09-09 14:00:51
*/
export async function updateUseCatalog ({ bookId, catalogId }) {
  const { data } = await axios.post(`${process.env.VUE_APP_UC_URL}/isch-c/user/book/progress/${bookId}/${catalogId}`);
  return data;
}
/*
 *@functionName: studentSetBookId
 *@params: 参数
 *@description:获取同事信息
 *@author: libaochuan
 *@date: 2020-09-11 09:33:31

*/
export async function studentSetBookId (body) {
  const { data } = await axios.post('/gw/ucsapi/isch-c/student/book/last',
    body,
    {
      transformRequest: [
        function (data) {
           let ret = '';
           for (const it in data) {
              ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&';
           }
           ret = ret.substring(0, ret.lastIndexOf('&'));
           return ret;
        }
      ],
      headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
      }
    }
  );
  return data;
}
/*
 *@functionName: studentGetBookId
 *@params: 参数
 *@description: 查询学生最新访问教材ID
 *@author: libaochuan
 *@date: 2020-09-11 09:33:31
*/
export async function studentGetBookId ({
  termCode,
  studyStageCode,
  gradeCode,
  subjectCode
}) {
  const { data } = await axios.get('/gw/ucsapi/isch-c/student/book/last/bookId', {
    params: {
      termCode,
      studyStageCode,
      gradeCode,
      subjectCode
    }
  });
  return data;
}
